package com.zyh.arraydemo;

import java.util.Scanner;

public class ArrayDemo5 {
    public static void main(String[] args) {
//        创建三个班级一维数组，并输入数据
        int[] class1 = new int[3];
        for (int i = 0; i < class1.length; i++) {
            System.out.println("请输入第一个班级的第" + (i + 1) + "个学生的成绩：");
            class1[i] = new Scanner(System.in).nextInt();
        }
        int[] class2 = new int[4];
        for (int i = 0; i < class2.length; i++) {
            System.out.println("请输入第二个班级的第" + (i + 1) + "个学生的成绩：");
            class2[i] = new Scanner(System.in).nextInt();
        }
        int[] class3 = new int[5];
        for (int i = 0; i < class3.length; i++) {
            System.out.println("请输入第三个班级的第" + (i + 1) + "个学生的成绩：");
            class3[i] = new Scanner(System.in).nextInt();
        }
//        创建二维数组学校，里面有三个子数组
        int[][] school = new int[3][];
        school[0] = class1;
        school[1] = class2;
        school[2] = class3;
//        遍历二维数组
        for (int i = 0; i < school.length; i++) {
//            定义school的子数组
            int[] clazz = school[i];
//            定义总和变量
            double sum = 0.0;
            for (int i1 = 0; i1 < clazz.length; i1++) {
                sum = sum + clazz[i];
            }
            System.out.println("第" + (i+1) + "班级的平均成绩是：" + sum / clazz.length);
        }
    }
}
